package com.zxbg.service.impl.systemtoolsServiceImpl;

import com.zxbg.dao.EmployeeDao;
import com.zxbg.dao.NavMenuDao;
import com.zxbg.domain.Internationalization;
import com.zxbg.domain.NavMenu;
import com.zxbg.service.systemtoolsService.MenuManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuManageServiceImpl implements MenuManageService {
    @Autowired
    NavMenuDao navMenuDao;
    @Autowired
    EmployeeDao employeeDao;
    @Autowired
    OrganizationalStructureServiceImpl organizationalStructureService;

    @Override
    public List<NavMenu> getAllNavMenu(Integer tenant_id) {
        List<NavMenu> navMenuList = navMenuDao.getAllNavMenu(tenant_id);
        for (int i = 0; i < navMenuList.size(); i++) {
            NavMenu temp = navMenuList.get(i);
            temp.setCreator(organizationalStructureService.getAllKindsDept(employeeDao.getEmployeeByEmployeeId(temp.getCreator_id(), tenant_id)));
            temp.setMenu_name(new Internationalization(temp.getMenu_name_zh(), temp.getMenu_name_en()));
        }
        return navMenuList;
    }

    @Override
    public boolean addNavMenu(NavMenu navMenu) {
        return navMenuDao.addNavMenu(navMenu) > 0;
    }

    @Override
    public boolean changeStatus(Integer menu_id, Integer status) {
        return navMenuDao.changeStatus(menu_id, status) > 0;
    }

    @Override
    public boolean editNavMenu(NavMenu navMenu) {
        return navMenuDao.editNavMenu(navMenu) > 0;
    }

    @Override
    public boolean deleteNavMenu(Integer menu_id) {
        return navMenuDao.deleteNavMenu(menu_id) > 0;
    }

    @Override
    public List<NavMenu> getNavMenuByKey(String key, Integer tenant_id) {
        List<NavMenu> navMenuList = navMenuDao.getNavMenuByKey("%" + key.replace("\"", "") + "%", tenant_id);
        for (int i = 0; i < navMenuList.size(); i++) {
            NavMenu temp = navMenuList.get(i);
            temp.setCreator(organizationalStructureService.getAllKindsDept(employeeDao.getEmployeeByEmployeeId(temp.getCreator_id(), tenant_id)));
            temp.setMenu_name(new Internationalization(temp.getMenu_name_zh(), temp.getMenu_name_en()));
        }
        return navMenuList;
    }
}
